'''
Created on 30/03/2009

@author: eh01
'''
from im.ds import dsconstants, dso
from im.ds.dso import DSO
from im.ds.dst import DST
from im.handler.speara2ahandler import SPEARA2AHandler
from im.speara2a import helper
from xml.etree import ElementTree
import unittest


class Test(unittest.TestCase):


    def setUp(self):
        pass


    def tearDown(self):
        pass


    def test_spear_a2a_handler_case1(self):
        # create web service name dst
        web_service_name_dst = DST(subject=dsconstants.SUBJECT_ROOT,
            predicate=dsconstants.PREDICATE_SPEAR_A2A_WEB_SERVICE_NAME,
            literal='LxSpearEcho')
        
        # create soap message
        access_token = helper.get_access_token()
        env = ElementTree.Element('{http://schemas.xmlsoap.org/soap/envelope/}Envelope')
        body = ElementTree.SubElement(env, '{http://schemas.xmlsoap.org/soap/envelope/}Body')
        echo = ElementTree.SubElement(body, '{http://test.webservice.spear.lx.dse.vic.gov.au}echo')
        echo.append(access_token)
        input = ElementTree.SubElement(echo,
            '{http://test.webservice.spear.lx.dse.vic.gov.au}input')
        input.text = "Hello Ed"
        soap = '<?xml version="1.0" encoding="utf-8" ?>\r\n' + ElementTree.tostring(env)
        
        soap_message_dst = DST(subject=dsconstants.SUBJECT_ROOT,
            predicate=dsconstants.PREDICATE_SOAP_MESSAGE,
            literal=soap)        
        
        dso = DSO([])
        dso.add_dst(soap_message_dst)
        dso.add_dst(web_service_name_dst)
        
        spear_a2a_handler = SPEARA2AHandler()
        spear_a2a_handler.do(dso)

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.test_spear_a2a_handler_case1']
    unittest.main()